import Vue from 'vue'
//路由方法集
import VRouter from 'vue-router'

//404页面
import NotFoundComponent from '@/components/other/NotFoundComponent'

//会员中心
import ownAll from '@/components/own/ownAll'
import own from '@/components/own'
import team from '../components/own/team'
import extend from '../components/own/extend'
import qrcode from '../components/own/qrcode'
import AddMember from '../components/own/AddMember'

import owninfos from '../components/own/owninfos'
import realname from '../components/owninfos/realname' 

import assets from '../components/own/assets'
import water from '../components/assets/water'
import trade from '../components/assets/trade'
import record from '../components/assets/record'

import setup from '../components/own/setup'
import phones from '../components/setup/phones'
import newphones from '../components/setup/newphones'
import modifypwd from '../components/setup/modifypwd'
import tipsetpwd from '../components/setup/tipsetpwd'
import setpwd from '../components/setup/setpwd'
import typepwd from '../components/setup/typepwd'
import oldpwd from '../components/setup/oldpwd'
import verpwd from '../components/setup/verpwd'
import bankcard from '../components/setup/bankcard'
import bankadd from '../components/setup/bankadd'
import bankinfo from '../components/setup/bankinfo'


//登录模块
import loginAll from '../components/Login/loginAll'
import ToLogin from '../components/Login/ToLogin'

Vue.use(VRouter)
let router = new VRouter({
	mode: 'history',
	routes: [{
			path: '/',
			name: '首页',
			redirect: '/ownAll',
			component: ownAll
		},
		{
			path: '*',
			name: '404页面',
			component: NotFoundComponent
		},
		{
			path: '/loginAll',
			name: '登录模块',
			component: loginAll,
			redirect: '/LoginAll/ToLogin',
			children: [{
				path: '/LoginAll/ToLogin',
				name: '用户登录',
				component: ToLogin
			}]
		},
		{
			path: '/ownAll',
			name: '会员',
			component: ownAll,
			redirect: '/ownAll/own',
			children: [{
					path: '/ownAll/own',
					name: '会员中心',
					component: own
				},
				{
					path: '/ownAll/assets',
					name: '我的资产',
					component: assets
				},
				{
					path: '/ownAll/team',
					name: '我的团队',
					component: team
				},
				{
					path: '/ownAll/extend',
					name: '我的推广',
					component: extend
				},
				{
					path: '/ownAll/owninfos',
					name: '个人资料',
					component: owninfos
				},
				{
					path: '/ownAll/qrcode',
					name: '二维码',
					component: qrcode
				},
				{
					path: '/ownAll/AddMember',
					name: '推荐新人',
					component: AddMember
				},
				{
					path: '/ownAll/setup',
					name: '设置',
					component: setup
				},
				{
					path: '/ownAll/phones',
					name: '手机绑定',
					component: phones
				},
				{
					path: '/ownAll/newphones',
					name: '更换手机',
					component: newphones
				},
				{
					path: '/ownAll/modifypwd',
					name: '密码管理',
					component: modifypwd
				},
				{
					path: '/ownAll/tipsetpwd',
					name: '初始密码',
					component: tipsetpwd
				},
				{
					path: '/ownAll/setpwd',
					name: '设置初始密码',
					component: setpwd
				},
				{
					path: '/ownAll/typepwd',
					name: '密码修改类型',
					component: typepwd
				},
				{
					path: '/ownAll/oldpwd',
					name: '旧密码密码修改',
					component: oldpwd
				},
				{
					path: '/ownAll/verpwd',
					name: '验证码修改',
					component: verpwd
				},
				{
					path: '/ownAll/bankcard',
					name: '银行卡管理',
					component: bankcard
				},
				{
					path: '/ownAll/bankadd',
					name: '添加银行卡',
					component: bankadd
				},
				{
					path: '/ownAll/bankinfo',
					name: '银行卡详情',
					component: bankinfo
				},
				{
					path: '/ownAll/realname',
					name: '推荐注册',
					component: realname
				},
				{
					path: '/ownAll/water',
					name: '积分流水',
					component: water
				},
				{
					path: '/ownAll/trade',
					name: '充值提现',
					component: trade
				},
				{
					path: '/ownAll/record',
					name: '充值提现记录',
					component: record
				} 
			]
		},

	]
});

router.beforeEach(function(to, from, next) {
	if(to.path === "/LoginAll/ToLogin") {
		next()
	} else {
		if(to.path === "/ownAll/realname"){
			next();
			return
		}
		if(!sessionStorage.MembersID) {
			next("/LoginAll/ToLogin")
		} else {
			next()
		}
	}

}); 
/*router.afterEach(function(to) {
	if(to.name) {
		document.title = to.name;
	}
});*/ 
export default router;